<template>
  <el-form :model="noticForm" ref="noticForm" label-width="20px" :inline="true" :rules="rules">
    <el-card>
      <h4 style="font-weight: 800">STEP1:选择款式</h4>
      <el-col :span="24">
        <el-row v-for="(noticItem, index) in noticForm.noticConfig" :key="index">
          <el-col :span="21" v-for="nameItem in noticItem.name" :key="nameItem.key">
            <el-form-item prop="productNo" label=" ">
              <!-- <el-input v-model="nameItem.productNo"></el-input> -->
              <el-select v-model="nameItem.productNo" clearable filterable remote :remote-method="getDatas"
                :loading="loading" placeholder="货号编码" @change="testAdd(nameItem.productNo, index, nameItem)"
                style="width: 150px">
                <el-option v-for="item in options" :key="item" :label="item" :value="item">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="colorProperty" label=" ">
              <!-- <el-input v-model="nameItem.colorProperty"></el-input> @focus="onFocus" remote
                :remote-method="getData"
              testSize(nameItem.size, nameItem.id)
              -->
              <el-select ref="selectRef" v-model="nameItem.colorProperty" clearable filterable placeholder="选择颜色" @change="
                testColor(
                  nameItem.productNo,
                  nameItem.colorProperty,
                  nameItem.id,
                  nameItem
                )
                " style="width: 200px">
                <el-option v-for="item in ColorLike" :key="item" :label="item" :value="item">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="size" label=" ">
              <!-- <el-select v-model="nameItem.size" placeholder="尺寸" clearable>
                        <el-option v-for="dict in dict.type.sys_product_size" :key="dict.value" :label="dict.label"
                            :value="dict.value" />
                    </el-select> -->
              <!-- <el-input v-model="nameItem.size"></el-input> ref="multiSelect" @focus="onFocus"-->
              <el-select ref="multiSelect" v-model="nameItem.size" clearable @focus="focusSize(nameItem)" placeholder="尺寸"
                style="width: 100px" @change="testSize(nameItem.size, nameItem.id)">
                <!--    -->
                <el-option v-for="item in sizeList" :key="item.id" :label="item.size" :value="item.size">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item @focus="onFocus" prop="productNum" label=" ">
              <el-input ref="autoFocus" v-model="nameItem.productNum" placeholder="购买数量" style="width: 110px"
                type="number" oninput="value=value.replace(/^0|[^0-9]/g,'')" @focus="testNum()"
                @change="handleBlur(nameItem)"></el-input>
            </el-form-item>
            <!-- @focus="getinput" -->
            <!-- <p placeholder="库存量">{{ nameItem.num }}</p> -->
            <!-- <div v-for="(item, index) in sizeArr" :key="index">
                                {{ item }}

                            </div> -->
            <!-- {{ sizeArr.slice(-1) }} -->
            <el-form-item prop="num" label="主图:" label-width="70px">
              <!-- {{ sizeArr[index] }} -->
              <!-- <div v-for="(item) in sizeArr">

                               
                            </div> -->
              <!-- {{ nameItem.id }} -->

              <!-- {{ imgArr[nameItem.id] }} pjtUrl + -->
              <image-preview :src="imgArr[nameItem.id]" alt="" style="width: 40px; height: 40px; object-fit: cover" />
            </el-form-item>
            <el-form-item prop="purchasePrice" label="内购单价:" label-width="80px">
              <el-input v-model="nameItem.purchasePrice" style="width: 100px"></el-input>
            </el-form-item>
            <el-form-item prop="num" label="库存量:" label-width="70px">
              <!-- {{ sizeArr[index] }} -->
              <!-- <div v-for="(item) in sizeArr">

                               
                            </div> -->
              <!-- {{ nameItem.id }} -->

              {{ sizeArr[nameItem.id] }}
            </el-form-item>
            <!-- <el-form-item prop="isReturn" label="是否归还" label-width="80px">
              
              <el-radio-group
                v-model="nameItem.isReturn"
                size="small"
                fill="#66b1ff"
              >
                <el-radio :label="'是'">是</el-radio>
                <el-radio :label="'否'">否</el-radio>
              </el-radio-group>
            </el-form-item> -->
          </el-col>
          <!-- <el-col :span="10" v-for="(phoneItem, index) in noticItem.phone" :key="phoneItem.key">
                <el-form-item prop="phone" label="电话：">
                    <el-input v-model="phoneItem.value"></el-input>
                </el-form-item>
            </el-col> -->
          <el-col :span="3">
            <el-button type="primary" size="mini" @click="addDomain(noticItem)">新增</el-button>
            <el-button type="danger" size="mini" @click.prevent="removeDomain(noticItem)">删除</el-button>
            <!-- <el-button type="primary" size="mini" @click="getinventory">查询</el-button> -->
          </el-col>
        </el-row>
      </el-col>

      <!-- <el-col :span="4" v-show="openPrice">
        <span
          >产品金额:{{ juShuiTanPrice.productAmount }}<br />
          运费金额:{{ juShuiTanPrice.shippingAmount }}<br />
          汇总金额:{{ juShuiTanPrice.totalAmount }}<br
        /></span>
        {"productAmount":99.5,"shippingAmount":5.0,"totalAmount":104.5}
          当前库存量：{{ sizeArr.slice(-1) }}<br />
      </el-col> -->
    </el-card>
    <el-card>
      <div slot="header">
        <span style="font-weight: 800; margin-right: 10px">STEP2:计算内购需支付金额</span>
        <el-button :disabled="this.single" type="primary" size="mini" @click="handlePrice">
          计算金额
        </el-button>
        <el-input v-model="shippingFee" style="width: 100px; margin-left: 10px" placeholder="指定运费"></el-input>
      </div>

      <el-table :data="juShuiTanPrice">
        <el-table-column label="商品件数" align="center" prop="productNum" />
        <el-table-column label="商品金额汇总" align="center" prop="productAmount" />
        <el-table-column label="运费金额" align="center" prop="shippingAmount">
          <template slot-scope="scope">
            <span v-if="scope.row.shippingAmount" style="
                color: rgb(37, 137, 255);
                cursor: pointer;
                text-decoration: underline;
                font-weight: bold;
              " @click="dialogVisible = true">
              {{ scope.row.shippingAmount }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="汇总金额" align="center" prop="totalAmount" />
      </el-table>
    </el-card>
    <el-dialog :visible.sync="dialogVisible" width="400px" append-to-body v-if="dialogVisible">
      <el-form label-width="120px">
        <el-form-item label="指定运费" prop="shippingFee">
          <el-input v-model="shippingFee" placeholder="指定运费" style="width: 150px"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handlePrice">计算金额 </el-button>
      </div>
    </el-dialog>
    <el-card>
      <h4 style="font-weight: 800">STEP3:转账并上传支付截图</h4>
      <el-row :inline="true">
        <!-- <el-form-item label=" " prop="payMethod" label-width="80px">
          <el-input
            v-model="sampleTalentPay.payMethod"
            placeholder="请输入支付方式"
          />
        </el-form-item> -->
        <!-- <el-form-item
          prop="expressCompany"
          label="快递公司:"
          label-width="90px"
        >
          
          <el-select
            :disabled="true"
            v-model="expressCompany"
            placeholder="请选择快递公司"
            clearable
            filterable
          >
            <el-option
              v-for="dict in dict.type.sys_jst_sample_sf"
              :key="dict.label"
              :label="dict.label"
              :value="dict.label"
            />
          </el-select>
        </el-form-item> -->
        <el-form-item prop="applyReason" label="申请理由:" label-width="90px">
          <el-input v-model="applyReason"></el-input>
        </el-form-item>

        <el-form-item prop="payAccount" label="" label-width="120px" style="margin-right: 20px">
          本次内购共计金额:<span style="font-weight: 800; margin-right: 10px">{{
            totalAmount
          }}</span>元，付款支付宝信息:
        </el-form-item>

        <el-form-item prop="payAccount" label="" label-width="120px">
          <span style="margin-right: 5px">内购支付宝账号:</span>
          {{ payAccount }}

          <!-- </el-form-item>

        <el-form-item prop="payName" label="支付宝名字:" label-width="120px"> -->
          <span style="margin-right: 5px">，支付宝名字:</span>
          {{ payName }}
        </el-form-item>
        <br />
        <el-form-item label="支付截图(必填)" label-width="120px" prop="logoUrl">
          <!-- <el-upload :action="imgUpload.url" :headers="imgUpload.headers" list-type="picture-card" :limit="limit"
                                                                                                                                    :on-exceed="handleExceed" :on-success="handlePictureSuccess" :before-upload="beforeAvatarUpload"
                                                                                                                                    :on-preview="handlePictureCardPreview" :file-list="fileList" :on-change="changeFile2">
                                                                                                                                    <i class="el-icon-plus"></i>
                                                                                                                                </el-upload>
                                                                                                                                <el-dialog :visible.sync="dialogVisible">
                                                                                                                                    <img width="100%" v-if="imageUrl" :src="imageUrl" alt="">
                                                                                                                                                                    </el-dialog> -->
          <el-upload ref="uploadlogourl" :action="imgUpload.url" :headers="imgUpload.headers" list-type="picture-card"
            :on-change="changelogourl" :file-list="filelogourl" multiple :on-success="uploadlogourl"
            :on-remove="Removelogourl">
            <i class="el-icon-plus"></i>
          </el-upload>
          <div id="preview" @paste="handlelogourl">
            <span><i class="el-icon-s-opportunity" style="color: #fb894c"></i>点击此处 将支付截图按Ctrl+V 粘贴至此处</span>
          </div>
        </el-form-item>

        <!-- <el-form-item label="支付账号" prop="payAccount" label-width="80px">
          <el-input
            v-model="sampleTalentPay.payAccount"
            placeholder="请输入支付账号"
          />
        </el-form-item>
        <el-form-item label="姓名" prop="payName" label-width="60px">
          <el-input
            v-model="sampleTalentPay.payName"
            placeholder="请输入姓名"
          />
        </el-form-item> -->
      </el-row>
    </el-card>

    <el-form-item style="width: 100%; text-align: center">
      <!-- <el-button @click="submitnote('noticForm')" type="primary"
        >笔记合作</el-button
      > -->
      <el-button @click="submithandlePrice" type="primary">申请内购</el-button>
      <el-button @click="resetForm" style="margin-left: 10px">一键清空</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
//数据获取
import { pcaa } from "area-data";
import axios from "axios";
const util = require("@/api/sample/util.js");
import { getApplyReason } from "@/api/internal/apply";

import {
  listTemplate,
  getTemplate,
  delTemplate,
  addTemplate,
  updateTemplate,
  addTemplateAndSecondry,
  addProNoColorSize,
  productNoLike,
} from "@/api/product/template";
import {
  listSecondry,
  getSecondry,
  delSecondry,
  addSecondry,
  updateSecondry,
  getInfoByName,
  productNoColorLike,
  listAll,
  colorLike,
  selectPicByProductNoColor,
} from "@/api/product/secondry";
import {
  listSample,
  getSample,
  delSample,
  addSample,
  updateSample,
  SampleTalentFirstAdd,
  inventory,
} from "@/api/sample/sample";
import {
  listInternal_purchase,
  getInternal_purchase,
  delInternal_purchase,
  addInternal_purchase,
  updateInternal_purchase,
  getSalepriceByProductno,
  calcTotalAmount,
  addApply,
  getPayaccount,
  addEditApply,
} from "@/api/internal/internal_purchase";
//--------导入token
import { getToken } from "@/utils/auth";
export default {
  name: "Ceshi",
  dicts: [
    "sys_product_qudao",
    "sys_product_size",
    "sys_product_coder",
    "sys_sample_sf",
    "sys_one_zero",
    "sys_sample_status",
    "sys_sample_name",
    "sys_sample_cj",
    "sys_jst_sample_sf",
  ],
  props: {
    contactId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      shippingFee: null,
      isPrice: false,
      // 禁用
      single: false,
      //申请理由
      applyReason: "",
      //内购支付账号
      payAccount: "",
      // 内购支付名字
      payName: "",
      logoUrl: "",
      filelogourl: [],
      upload_list: [], //提交的图片数组
      //图片相对路径
      // picurl: '',
      // //图片地址
      // picUrl: '',
      //logo相对路径
      // logoUrl: '',
      pjtUrl: process.env.VUE_APP_BASE_API,
      // 图片数量限制
      limit: 1,

      dialogVisible: false,
      imgUpload: {
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
        },
        // 图片上传的方法地址:
        url: process.env.VUE_APP_BASE_API + "/common/upload",
      },

      //聚水潭响应
      openPrice: false,
      juShuiTanPrice: [],
      totalAmount: 0,
      sizeArr: [],
      imgArr: [],
      count: 1,

      //库存量
      num: "",
      demo: "",
      //省市区
      pcaaData: pcaa,
      // 区域数据
      provinces: pcaa["86"],
      citys: [],
      areas: [],
      //
      productNo: "",
      colorProperty: "",
      size: "",
      // 遮罩层
      loading: true,
      //模糊匹配
      sizeList: [],
      ColorLike: [],
      options: [], // 选项，从后端传递过来
      sampleTalentCooperateType: "",
      expressCompany: "中通快递",
      //data
      noticForm: {
        noticConfig: [
          {
            name: [
              {
                // value: "",
                // phone: "",
                productNo: "",
                colorProperty: "",
                size: "",
                productNum: "",

                id: 0,
                purchasePrice: "",
                // expressCompany: "",
              },
            ],
            // phone: [
            //     {
            //         value: "",
            //     },
            // ],
          },
        ],
      },

      sampleTalentContact: {
        phone: "",
        receiverCity: "",
        receiverDistrict: "",
        receiverState: "",
        recipient: "",
        address: "",
      },
      sampleTalentInfo: {
        platform: "",
        platformId: "",
        talentLevel: "",
        xhsNickname: "",
        contactPerson: "",
        recommendSituation: "",
        reason: "",
        homeLink: "",
        fansNum: "",
        likeNum: "",
        cooperatePrice: "",
        talentStatus: "",
        contactWechat: "",
      },
      sampleTalentPay: {
        payAccount: "",
        payImage: "",
        payMethod: "",
        payName: "",
        platform: "",
      },

      // 表单校验
      rules: {
        productNo: [
          { required: true, message: "货号不能为空", trigger: "blur" },
        ],
        colorProperty: [
          { required: true, message: "颜色不能为空", trigger: "blur" },
        ],
        size: [{ required: true, message: "尺寸不能为空", trigger: "blur" }],
        // productNum: [
        //     { required: true, message: "购买数量不能为空", trigger: "blur" }
        // ],
        // platform: [
        //     { required: true, message: "平台名称不能为空", trigger: "blur" }
        // ],
        // platformId: [
        //     { required: true, message: "平台ID不能为空", trigger: "blur" }
        // ],
        // xhsNickname: [
        //     { required: true, message: "昵称不能为空", trigger: "blur" }
        // ],
        // phone: [
        //     { required: true, message: "电话不能为空", trigger: "blur" }
        // ],
      },
    };
  },
  created() {
    // this.provincearr = province
    // this.getList();
    getApplyReason().then((response) => {
      this.applyReason = response.msg;
    });

    getPayaccount().then((response) => {
      this.payAccount = response.data.payAccount;
      this.payName = response.data.payName;
    });
  },
  methods: {
    focusSize(nameItem) {
      listAll({ productNo: nameItem.productNo, colorProperty: nameItem.colorProperty }).then(
        (res) => {
          // this.loading = false;
          this.sizeList = res;
          console.log(JSON.stringify(res));
        }
      );
    },
    // addText() {
    //   if (!this.demo) {
    //     this.$modal.msgError("请输入内容");
    //     return;
    //   }

    //   let address = this.demo.replace(/\s+/g, " ");
    //   console.log(JSON.stringify(address));
    //   axios({
    //     method: "get",
    //     url: "https://v.api.aa1.cn/api/api-kdjx/index.php",
    //     params: {
    //       msg: address,
    //     },
    //   }).then((res) => {
    //     console.log(JSON.stringify(res.data));
    //     let m = res.data.newslist[0];
    //     this.sampleTalentContact.phone = m.mobile ? m.mobile : "";
    //     this.sampleTalentContact.recipient = m.name ? m.name : "";
    //     this.sampleTalentContact.receiverState = m.province ? m.province : "";
    //     this.sampleTalentContact.receiverCity = m.city ? m.city : "";
    //     this.sampleTalentContact.receiverDistrict = m.district
    //       ? m.district
    //       : "";
    //     this.sampleTalentContact.address = m.detail;

    //     this.seletekey(this.sampleTalentContact.receiverState, "province");
    //     this.seletekey(this.sampleTalentContact.receiverCity, "city");
    //     this.seletekey(this.sampleTalentContact.receiverDistrict, "area");
    //   });
    // },
    addText() {
      if (!this.demo) {
        this.$modal.msgError("请输入内容");
        return;
      }

      let address = this.demo.replace(/\s+/g, " ");
      console.log(JSON.stringify(address));
      axios({
        method: "post",
        url: "https://wangzc.wang/smAddress",
        // url: "http://47.97.123.182:1399/smAddress",
        data: {
          address: address,
        },
      }).then((res) => {
        this.sampleTalentContact.phone = res.data.phone ? res.data.phone : "";
        this.sampleTalentContact.recipient = res.data.name ? res.data.name : "";
        this.sampleTalentContact.receiverState = res.data.province
          ? res.data.province
          : "";
        this.sampleTalentContact.receiverCity = res.data.city
          ? res.data.city
          : "";
        this.sampleTalentContact.receiverDistrict = res.data.county
          ? res.data.county
          : "";
        this.sampleTalentContact.address = res.data.street
          ? res.data.street + res.data.address
          : res.data.address;

        this.seletekey(this.sampleTalentContact.receiverState, "province");
        this.seletekey(this.sampleTalentContact.receiverCity, "city");
        this.seletekey(this.sampleTalentContact.receiverDistrict, "area");
      });
    },
    testsampleTalentCooperateType(val) {
      console.log(val);
      this.sampleTalentCooperateType = val;
    },
    //计算金额
    handlePrice() {
      if (!this.productNo) {
        this.$modal.msgError("请选择购买数量后计算");
        return;
      }
      this.dialogVisible = false;
      this.juShuiTanPrice = [];
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      console.log(JSON.stringify(apply));
      const hasEmptyProductNo = apply.some(
        (product) => product.productNo == ""
      );
      if (hasEmptyProductNo) {
        this.$modal.msgError("检查货号编码是否为空");
        return;
      }
      const hasEmptycolorProperty = apply.some(
        (product) => product.colorProperty == ""
      );
      if (hasEmptycolorProperty) {
        this.$modal.msgError("检查颜色属性是否为空");
        return;
      }
      const hasEmptysize = apply.some((product) => product.size == "");
      if (hasEmptysize) {
        this.$modal.msgError("检查尺寸是否为空");
        return;
      }
      const hasEmptyProductNum = apply.some(
        (product) => product.productNum == ""
      );
      if (hasEmptyProductNum) {
        this.$modal.msgError("检查购买数量是否为空");
        return;
      }

      // const totalCount = apply.reduce((accumulator, currentItem) => {
      //   if (!currentItem.productNum) {
      //     this.$modal.msgError("检查购买数量是否为空");
      //     return;
      //   }
      //   return accumulator + parseFloat(currentItem.productNum);
      // }, 0); // 初始值设为0
      // if (totalCount > 3) {
      //   this.$modal.msgError("请选择商品件数小于3件");
      //   return;
      // }

      // calcTotalAmount({ internalPurchaseApplyItemVoList: apply }).then(
      //   (response) => {
      //     this.$modal.closeLoading();
      //     this.juShuiTanPrice.push(response);

      //     if (response.resultCode == 500) {
      //       this.$alert("购买数量超过3件，请修改。", "提示", {
      //         confirmButtonText: "确定",
      //         showConfirmButton: false,
      //       });
      //     }

      //     this.openPrice = true;
      //   }
      // );

      this.single = true;

      this.openLoading();

      let value = {
        internalPurchaseApplyItemVoList: apply,
        shippingFee: parseInt(this.shippingFee),
      };
      axios({
        method: "post",
        // url: "http://47.107.129.160:9001/prod-api/product/parsing",
        url: process.env.VUE_APP_BASE_API + "/product/apply/calcTotalAmount",
        data: value,
        headers: {
          // header: { responseType: "blob" },

          Authorization: "Bearer " + getToken(),
        }, //定义内容格式,很重要
        // data: obj,
      }).then((response) => {
        this.$modal.closeLoading();
        console.log(response);
        if (response.data.resultCode == 500) {
          this.juShuiTanPrice.push(response.data);
          this.$alert("没有购买超过3件的权限，请联系管理员!", "提示", {
            confirmButtonText: "确定",
            showConfirmButton: false,
          });
        }

        this.juShuiTanPrice.push(response.data);
        this.totalAmount = response.data.totalAmount;
        this.isPrice = true;

        this.single = false;
      }, 2000);
    },
    //计算金额
    submithandlePrice() {
      if (!this.productNo) {
        this.$modal.msgError("请选择购买数量后计算");
        return;
      }
      this.juShuiTanPrice = [];
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      const hasEmptyProductNo = apply.some(
        (product) => product.productNo == ""
      );
      if (hasEmptyProductNo) {
        this.$modal.msgError("检查货号编码是否为空");
        return;
      }
      const hasEmptycolorProperty = apply.some(
        (product) => product.colorProperty == ""
      );
      if (hasEmptycolorProperty) {
        this.$modal.msgError("检查颜色属性是否为空");
        return;
      }
      const hasEmptysize = apply.some((product) => product.size == "");
      if (hasEmptysize) {
        this.$modal.msgError("检查尺寸是否为空");
        return;
      }
      const hasEmptyProductNum = apply.some(
        (product) => product.productNum == ""
      );
      if (hasEmptyProductNum) {
        this.$modal.msgError("检查购买数量是否为空");
        return;
      }
      // const totalCount = apply.reduce((accumulator, currentItem) => {
      //   if (!currentItem.productNum) {
      //     this.$modal.msgError("检查购买数量是否为空");
      //     return;
      //   }
      //   return accumulator + parseFloat(currentItem.productNum);
      // }, 0); // 初始值设为0
      // if (totalCount > 3) {
      //   this.$modal.msgError("请选择商品件数小于3件");
      //   return;
      // }
      this.openLoading();

      calcTotalAmount({
        internalPurchaseApplyItemVoList: apply,
        shippingFee: parseInt(this.shippingFee),
      }).then((response) => {
        this.$modal.closeLoading();
        this.juShuiTanPrice.push(response);
        if (response.resultCode == 500) {
          this.$alert("没有购买超过3件的权限，请联系管理员!", "提示", {
            confirmButtonText: "确定",
            showConfirmButton: false,
          });
          return;
        } else if (response.resultCode == 200) {
          this.submitlive();
        }
        // if (response.resultCode == 500) {
        //   this.$alert("购买数量超过3件，请修改。", "提示", {
        //     confirmButtonText: "确定",
        //     showConfirmButton: false,
        //   });
        //   return;
        // } else if (response.resultCode == 200) {
        //   this.submitlive();
        // }
        // this.juShuiTanPrice.push(response);
        // this.openPrice = true;
      });
    },
    submitlive() {
      // console.log(JSON.stringify(this.contactId));
      // return;
      // if (!this.sampleTalentInfo.platform) {
      //   this.$modal.msgError("请输入平台名称");
      //   return;
      // }
      // if (!this.sampleTalentInfo.platformId) {
      //   this.$modal.msgError("请输入平台ID");
      //   return;
      // }
      // if (!this.sampleTalentInfo.xhsNickname) {
      //   this.$modal.msgError("请输入昵称");
      //   return;
      // }
      // if (!this.sampleTalentContact.phone) {
      //   this.$modal.msgError("请输入电话");
      //   return;
      // }
      // if (!this.sampleTalentContact.recipient) {
      //   this.$modal.msgError("请输入收件人");
      //   return;
      // }
      // if (!this.sampleTalentContact.receiverState) {
      //   this.$modal.msgError("请选择省份");
      //   return;
      // }
      // if (!this.sampleTalentContact.receiverCity) {
      //   this.$modal.msgError("请选择城市");
      //   return;
      // }
      // if (!this.sampleTalentContact.receiverDistrict) {
      //   this.$modal.msgError("请选择县区");
      //   return;
      // }
      if (this.upload_list.length == 0) {
        this.$modal.msgError("请上传支付截图");
        return;
      }

      // == 'live'
      console.log(this.sampleTalentCooperateType);
      // if (!this.sampleTalentCooperateType.includes('live')) {
      //     this.$modal.msgError('请选择直播类型')
      //     return
      // }
      // return
      console.log(JSON.stringify(this.noticForm.noticConfig));

      // this.noticForm.noticConfig.forEach(item => {
      //     note.push(item.name)
      // })
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      const totalCount = apply.reduce((accumulator, currentItem) => {
        if (!currentItem.productNum) {
          this.$modal.msgError("检查购买数量是否为空");
          return;
        }
        return accumulator + parseFloat(currentItem.productNum);
      }, 0); // 初始值设为0
      // if (totalCount > 3) {
      //   this.$modal.msgError("请选择商品件数小于3件");
      //   return;
      // }
      var live = [];
      apply.forEach((item) => {
        live.push({
          payAccount: this.payAccount,
          payName: this.payName,
          applyReason: this.applyReason,
          contactId: this.contactId,
          paymentUrl: this.upload_list[0],
          // paymentUrlList: this.upload_list,
          expressCompany: this.expressCompany,
          ...item,
        });
      });

      console.log(JSON.stringify(live));
      var liveList = {
        shippingFee: parseInt(this.shippingFee),
        internalPurchaseApplyItemVoList: live,
      };
      // if (!liveList.sampleTalentApplyVOList[0].productNo) {
      //   this.$modal.msgError("请选择款式");
      //   return;
      // }
      // if (!liveList.sampleTalentApplyVOList[0].colorProperty) {

      //     this.$modal.msgError('请选择颜色')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].size) {

      //     this.$modal.msgError('请选择尺寸')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].productNum) {

      //     this.$modal.msgError('请输入购买数量')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].isReturn) {

      //     this.$modal.msgError('请选择是否归还')
      //     return
      // }
      // if (liveList.sampleTalentApplyVOList[1]) {
      //   if (!liveList.sampleTalentApplyVOList[1].productNo) {
      //     this.$modal.msgError("请选择第二个款式");
      //     return;
      //   }
      // }

      // return
      console.log(JSON.stringify(liveList));
      addEditApply(liveList).then((res) => {
        console.log(res);
        if (res.msg == "操作完成！") {
          this.$modal.msgSuccess("操作完成");
          // this.data = {};
          // window.location.reload();
          //清空数据
          this.resetForm();
          this.$router.push({
            path: "/internal/internalOrder",
            // query: { platformId: this.sampleTalentInfo.platformId },
          });
          // location.reload();
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },
    resetForm() {
      this.noticForm = {
        noticConfig: [
          {
            name: [
              {
                productNo: "",
                colorProperty: "",
                size: "",
                productNum: "",
                purchasePrice: "",
                id: 0,
              },
            ],
          },
        ],
      };
      this.sampleTalentContact = {};
      this.sampleTalentInfo = {};
      this.sampleTalentPay = {};
      this.sizeArr = [];
      this.imgArr = [];
      this.filelogourl = [];
      this.upload_list = [];
      this.juShuiTanPrice = [];
      this.totalAmount = 0;
    },
    submitnote() {
      if (!this.sampleTalentInfo.platform) {
        this.$modal.msgError("请输入平台名称");
        return;
      }
      if (!this.sampleTalentInfo.platformId) {
        this.$modal.msgError("请输入平台ID");
        return;
      }
      if (!this.sampleTalentInfo.xhsNickname) {
        this.$modal.msgError("请输入昵称");
        return;
      }
      if (!this.sampleTalentContact.phone) {
        this.$modal.msgError("请输入电话");
        return;
      }
      if (!this.sampleTalentContact.recipient) {
        this.$modal.msgError("请输入收件人");
        return;
      }
      if (!this.sampleTalentContact.receiverState) {
        this.$modal.msgError("请选择省份");
        return;
      }
      if (!this.sampleTalentContact.receiverCity) {
        this.$modal.msgError("请选择城市");
        return;
      }
      if (!this.sampleTalentContact.receiverDistrict) {
        this.$modal.msgError("请选择县区");
        return;
      }
      if (!this.sampleTalentContact.address) {
        this.$modal.msgError("请输入详细地址");
        return;
      }

      // if (!this.sampleTalentPay.payMethod) {

      // this.$modal.msgError('请输入支付方式')
      // return
      // }
      // if (!this.sampleTalentPay.payMethod) {

      // this.$modal.msgError('请输入支付方式')
      // return
      // }
      // if (!this.sampleTalentPay.payMethod) {

      //     this.$modal.msgError('请输入支付方式')
      //     return
      // }
      // if (!this.sampleTalentPay.payMethod) {

      //     this.$modal.msgError('请输入支付方式')
      //     return
      // }
      // if (!this.sampleTalentCooperateType.includes('note')) {
      //     this.$modal.msgError('请选择笔记类型')
      //     return
      // }
      // var apply = this.noticForm.noticConfig.map(item => item.name[0])
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      console.log(JSON.stringify(apply));
      var live = [];
      apply.forEach((item) => {
        live.push({
          applyReason: this.applyReason,
          expressCompany: this.expressCompany,
          ...item,
        });
      });

      var liveList = {
        sampleTalentCooperateType: "note",
        sampleTalentApplyVOList: live,
        sampleTalentContact: { ...this.sampleTalentContact },
        sampleTalentInfo: { ...this.sampleTalentInfo },
        sampleTalentPay: { ...this.sampleTalentPay },
      };
      console.log(JSON.stringify(liveList));
      if (!liveList.sampleTalentApplyVOList[0].productNo) {
        this.$modal.msgError("请选择款式");
        return;
      }
      // if (!liveList.sampleTalentApplyVOList[0].colorProperty) {

      //     this.$modal.msgError('请选择颜色')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].size) {

      //     this.$modal.msgError('请选择尺寸')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].productNum) {

      //     this.$modal.msgError('请输入购买数量')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].isReturn) {

      //     this.$modal.msgError('请选择是否归还')
      //     return
      // }
      if (liveList.sampleTalentApplyVOList[1]) {
        if (!liveList.sampleTalentApplyVOList[1].productNo) {
          this.$modal.msgError("请选择第二个款式");
          return;
        }
      }
      // return
      SampleTalentFirstAdd(liveList).then((res) => {
        console.log(res);
        if (res.msg == "操作完成！") {
          this.$modal.msgSuccess("操作完成");
          this.$router.push({
            path: "/sample/sample",
            // query: { platformId: this.sampleTalentInfo.platformId },
          });
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },

    // 新增
    removeDomain(item) {
      var index = this.noticForm.noticConfig.indexOf(item);
      if (index == "0") {
        // 还有一个的时候提示不能删除
        this.$message({
          message: "不能删除了",
          type: "error",
        });
        return false;
      }
      if (index !== -1 && index !== "0") {
        this.noticForm.noticConfig.splice(index, 1);
      }
    },
    // 表单新增
    addDomain(item) {
      console.log(
        JSON.stringify(this.noticForm.noticConfig[0].name[0].isReturn)
      );
      var m = item.name[0];
      if (!m.productNo) {
        this.$modal.msgError("请选择款式");
        return;
      }
      // if (!m.colorProperty) {
      //   this.$modal.msgError("请选择颜色");
      //   return;
      // }
      // if (!m.size) {
      //   this.$modal.msgError("请选择尺寸");
      //   return;
      // }
      // if (!m.productNum) {
      //   this.$modal.msgError("请输入购买数量");
      //   return;
      // }
      // if (!m.isReturn) {
      //   this.$modal.msgError("请选择是否归还");
      //   return;
      // }
      // var i = 0
      // if(m.isReturn){

      // }
      this.noticForm.noticConfig.push({
        name: [
          {
            // value: "",

            // phone: "",
            productNo: "",
            colorProperty: "",
            size: "",
            productNum: "",
            purchasePrice: "",
            // isReturn: this.noticForm.noticConfig[0].name[0].isReturn,
            id: this.count++,
            // num: "",
            // expressCompany: "",
            key: Date.now(),
          },
        ],
        // phone: [
        //     {
        //         value: "",
        //         key: Date.now() + "2",
        //     },
        // ],
      });
    },
    getinput() {
      console.log(JSON.stringify(this.noticForm.noticConfig));
    },
    //修改对话框
    /* 获取颜色列表 */
    getSize(key) {
      console.log(JSON.stringify(key));
      // this.loading = true;
      // return
      // listAll({ productNo: this.form.productNo, colorProperty: this.form.colorProperty }).then((res) => {
      //     // this.loading = false;
      //     this.sizeList = res
      //     console.log(JSON.stringify(res));
      // });
    },

    /* 获取颜色列表 */
    getData(key) {
      console.log(JSON.stringify(key));
      // this.loading = true;
      // return
      // colorLike(key).then((res) => {
      //     // this.loading = false;
      //     this.ColorLike = res.data;
      //     console.log(JSON.stringify(this.ColorLike));
      // });
    },
    getinventory() {
      inventory({
        productNo: this.productNo,
        colorProperity: this.colorProperty,
        size: this.form.size,
      }).then((res) => {
        // console.log(JSON.stringify(res.data));
        if (res.code == 200) {
          this.num = res.data[0].virtual_qty;
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },
    testNum(index) {
      // this.num = JSON.parse(localStorage.getItem("num"))
    },
    // 打开加载层
    openLoading2() {
      this.$modal.loading("正在读取聚水潭库存，请稍侯！");
    },
    // 打开加载层
    openLoading() {
      this.$modal.loading("正在加载，请稍候！");
    },
    testSize(key, index) {
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      const hasEmptyProductNo = apply.some(
        (product) => product.productNo == ""
      );
      if (hasEmptyProductNo) {
        this.$modal.msgError("检查货号编码是否为空");
        return;
      }
      const hasEmptycolorProperty = apply.some(
        (product) => product.colorProperty == ""
      );
      if (hasEmptycolorProperty) {
        this.$modal.msgError("检查颜色属性是否为空");
        return;
      }
      const hasEmptysize = apply.some((product) => product.size == "");
      if (hasEmptysize) {
        this.$modal.msgError("检查尺寸是否为空");
        return;
      }
      console.log(JSON.stringify(key));
      this.size = key;
      // console.log(this.count);
      console.log(index);
      this.openLoading2();
      inventory({
        productNo: this.productNo,
        colorProperity: this.colorProperty,
        size: this.size,
      }).then((res) => {
        this.$modal.closeLoading();

        if (res.code == 200) {
          if (res.data.length > 0) {
            if (res.data[0].publicCanUseNum < 5) {
              this.$alert(
                `货号:${this.productNo}，颜色：${this.colorProperty}，码数：${this.size}，库存不足，仅${res.data[0].publicCanUseNum}件，请慎重申请。`,
                "温馨提醒",
                {
                  confirmButtonText: "我知道了",
                  // showConfirmButton: false,
                }
              ).then(() => { });
            }
            this.sizeArr[index] = res.data[0].publicCanUseNum;
            console.log(JSON.stringify(this.sizeArr[index]));
            console.log(JSON.stringify(this.sizeArr));
            this.$forceUpdate();
          } else {
            this.$alert("该商品编码聚水潭不存在，请核对。", "提示", {
              confirmButtonText: "我知道了",
              // showConfirmButton: false,
            }).then(() => { });
            // this.$modal.msgError("该商品编码聚水潭不存在，请核对。");
          }
        } else {
          this.$alert("该商品编码聚水潭不存在，请核对。", "提示", {
            confirmButtonText: "我知道了",
            // showConfirmButton: false,
          }).then(() => { });
          // this.$modal.msgError(res.msg);
        }
      });
      // setTimeout(() => {
      //   this.$refs[multiSelect].blur();
      // }, 50);

      // this.$refs[multiSelect].blur();
    },
    //判断是否大于库存
    handleBlur(nameItem) {
      console.log(JSON.stringify(nameItem));
      if (nameItem.productNum > this.sizeArr[nameItem.id]) {
        this.$alert(
          "下单购买数量大于当前库存，请调整购买数量或者商品。",
          "提示",
          {
            confirmButtonText: "确定",
            showConfirmButton: false,
          }
        );
      }
    },
    /* 获取尺寸列表 */
    testColor(productNo, colorProperty, index, nameItem) {
      nameItem.size = "";
      this.colorProperty = colorProperty;
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      const hasEmptyProductNo = apply.some(
        (product) => product.productNo == ""
      );
      if (hasEmptyProductNo) {
        this.$modal.msgError("检查货号编码是否为空");
        return;
      }
      const hasEmptycolorProperty = apply.some(
        (product) => product.colorProperty == ""
      );
      if (hasEmptycolorProperty) {
        this.$modal.msgError("检查颜色属性是否为空");
        return;
      }
      listAll({ productNo: productNo, colorProperty: colorProperty }).then(
        (res) => {
          // this.loading = false;
          this.sizeList = res;
          console.log(JSON.stringify(res));
        }
      );

      this.openLoading();
      selectPicByProductNoColor({
        productNo: this.productNo,
        colorProperity: this.colorProperty,
        // size: this.size,
      }).then((res) => {
        this.$modal.closeLoading();
        this.imgArr[index] = res ? res : "";
      });
    },
    /* 获取颜色列表 */
    testAdd(key, index, nameItem) {
      nameItem.colorProperty = "";
      nameItem.size = "";
      this.productNo = key;
      console.log();
      if (!key) {
        return;
      }
      productNoColorLike({ productNo: key }).then((res) => {
        // this.loading = false;
        this.ColorLike = res.data;
        console.log(JSON.stringify(this.ColorLike));
      });
      getSalepriceByProductno(key).then((response) => {
        // this.sizeArr[index] = response;
        this.noticForm.noticConfig[index].name[0].purchasePrice = "";
        this.noticForm.noticConfig[index].name[0].purchasePrice = response;
      });
    },

    /* 获取货号列表 */
    getDatas(key) {
      console.log(JSON.stringify(key));
      this.loading = true;
      // return
      productNoLike(key).then((res) => {
        this.loading = false;
        this.options = res.data;
        console.log(JSON.stringify(this.options));
      });
    },
    //修改对话框
    //添加颜色列表获得焦点
    onFocus() {
      this.getData();

      this.getSize();
      // if (!this.form.colorProperty) {
      //     this.$selectRef.value.blur() //就是这一句，
      // }
    },
    seletekey(e, type) {
      if (e) {
        switch (type) {
          case "province":
            Object.keys(this.provinces).filter((item) => {
              if (this.provinces[item] === e) {
                this.citys = this.pcaaData[item];
              }
            });
            break;
          case "city":
            Object.keys(this.citys).filter((item) => {
              if (this.citys[item] === e) {
                this.areas = this.pcaaData[item];
              }
            });
            break;
          case "area":
            this.sampleTalentContact.receiverDistrict = e;
            this.$forceUpdate();
            break;
        }
      }
    },
    //logo图片
    handlelogourl(event) {
      const items = (event.clipboardData || window.clipboardData).items;
      let file = null;
      if (!items || items.length === 0) {
        this.$message.error("当前浏览器不支持本地");
        return;
      }
      // 搜索剪切板items
      for (let i = 0; i < items.length; i++) {
        if (items[i].type.indexOf("image") !== -1) {
          file = items[i].getAsFile();
          break;
        }
      }
      if (!file) {
        this.$message.error("粘贴内容非图片");
        return;
      }
      if (this.upload_list.length >= this.limit) {
        this.$message.error(`上传文件不能超过 ${this.limit} 个!`); // 图片购买数量超出
        return;
      }
      this.$refs.uploadlogourl.handleStart(file); // 将粘贴过来的图片加入预上传队列
      this.$refs.uploadlogourl.submit(); // 提交图片上传队列
    },
    //上传
    changelogourl(file, fileList) {
      // this.fileList = fileList
      // console.log("成功", file, fileList);
      // console.log(JSON.stringify(file));
      // console.log(JSON.stringify(fileList));
      // if (fileList.length > 3) {
      //   this.filelogourl = fileList.slice(-1);
      //   this.upload_list = this.upload_list.slice(-1);
      // }
      // console.log(JSON.stringify(this.upload_list));
      // console.log(JSON.stringify("filelogourl", this.filelogourl));
      this.filelogourl = fileList;
      // if (this.filelogourl.length > 2) {
      //   this.filelogourl.shift();
      //   this.filelogourl.push(file.response.fileName);
      // } else {
      //   this.filelogourl.push(file.response.fileName);
      // }
    },
    Removelogourl(file, fileList) {
      console.log(JSON.stringify(file));
      // console.log(JSON.stringify(fileList));
      // this.logoUrl = "";
      // this.filelogourl = fileList;

      var index = this.upload_list.indexOf(file.response.fileName);
      console.log(index);
      this.upload_list.splice(index, 1);
      console.log(JSON.stringify(this.upload_list));
    },

    uploadlogourl(res, file, fileList) {
      // this.logoUrl = file.response.fileName;
      if (this.upload_list.length > 2) {
        this.upload_list.shift();
        this.upload_list.push(file.response.fileName);
      } else {
        this.upload_list.push(file.response.fileName);
      }

      console.log(JSON.stringify(this.upload_list));
    },
  },
};
</script>
内购款式信息(必填)
货号编码
选择颜色
购买购买数量